$(function(){
	var self=this;
	$('#loginAndRegister').tabs();
	var usr=$('.username'),pwd=$('.password'),codetxt=$('.codetxt');
	codetxt.val('输入验证码')
	usr.val('用戶名');
	pwd.val('....');
	usr.focus(function(){
		this.value=""
	});
	codetxt.keyup(function(){
		var code=this.value,
	    length=code.length;
	if(length==4){
		$.ajax({ url: 'checkCode',
		     type:"post",
		     contentType : 'application/json', 
		     data:code,
		     success: function(data){
		    	 if(data=='0'){
		    		 changeValiImage('resources/images/right.gif');
		    		 isRight=true;
		    	 }else{
		    		 changeValiImage('resources/images/wrong.gif');
		    	 }
		    	 
	         },
	         error : function(error){
	        	 if(error)$.messager.alert("提示", error);
	         }
	     });
	}
	});
	var isRight;
	var submit=$('#submit');
	submit.click(function(){
		var loginForm=$('#loginForm');
		if(isRight)loginForm.submit();
		else{
			var msginfo=$('.msgInfo');
			if(msginfo)msginfo.remove();
			$('.loginbox').append("<span class='msgInfo' >请输入验证码！</span>");
			return false;
		}
	});
	var regist=$('#regist');
	regist.click(function(){
		location.href='register';
	});
	codetxt.blur(function(){
		if(this.value=='')this.value="输入验证码";
	});
	function changeValiImage(src){
		$('.msgImg').css('background',"url('"+src+"')");
	}
	codetxt.focus(function(){
		if(this.value=='输入验证码')this.value="";
	});
	pwd.focus(function(){
		this.value="";
	});
	var kaptImg=$('#kaptchaImage');
	kaptImg.click(function(){
		$(this).hide().attr('src','kaptchaImage?'+ Math.floor(Math.random() * 100)).fadeIn();
		event.cancelBubble = true;
	});
	var uploadbtn=$('#upload');
	uploadbtn.click(function(){
		var filename=$('#fileupload').val();
		if(!filename)return;
		$.ajaxFileUpload({
		        url: 'upload', //用于文件上传的服务器端请求地址
		        secureuri: false,
		        fileElementId: 'fileUpload', 
		        dataType: 'json',//返回值类型 一般设置为json
		        complete: function (data){//只要完成即执行，最后执行
		             alert(data);
		        },
		        success: function (data){alert(data);},
		        error: function (){}
		    });
	});
});